define(function(require, exports, module) {
	'use strict';
    
    var rk = require('rk');
    
    
    require('../su/accordion/oaTabCtrl');
    
    require('./groupPanelTableCtrl');
    //引入jstree
    $.widget('rk.groupPanelCtrl', $.rk.oaPanelCtrl, {
        _create: function () {
            var me = this;
            var elem = me.element;
            //1，模板文件请在WEB-INFO/templates/oa中追加
            //2，请在src/resources/sub-deps/oa中引入
            //3，如下所示，调用rk.template方法生成html
            //var html = rk.template("tpl_colleague_panel", {});//在子页面的jsp或/WEB-INF/templates/中定义
            //var temp = require('oa/tmpl/colleague/tpl_colleague_panel.tpl');
            //var html = rk.templateText(temp,{});
            //将html显示在elem中
            //elem.html(html);

            var temp = require('oa/tmpl/group/tpl_group_panel.tpl');
            var html = rk.templateText(temp,{});
            elem.html(html);
            me._listeners();
        },
        _listeners: function () {
            var me = this;
            var elem = me.element;
            elem.on("click", "[act='group_title_tab_button']", function(){
                var tab = $(this);
                var table_name = tab.attr("tab-name");
                if(elem.find("[tab-span-name='"+table_name+"']").hasClass("active")){
                    return;
                }
                elem.find("[act='group_title_tab_table']").hide();
                elem.find("[table-name='"+table_name+"']").show();
                elem.find("[act='group_title_tab']").removeClass("active");
                elem.find("[tab-span-name='"+table_name+"']").addClass("active");
                me.loaddata(table_name);
            });
            elem.find("[act='groupTypeSelect']").selectmenu({
                change: function () {
                    var type = elem.find("[act='groupTypeSelect']").val();
                    if(type == "work_joinedG"){
                        me.loaddata("my_group");
                    }else if(type == "work_adminG"){
                        me.loaddata("my_create_group");
                    }
                }
            });
            elem.on("click", "[act='group_create_new']", function(){
                require.async(["./content/groupCreateNewCtrl"],function(){
                    rk.dialog({
                        title: rk.i18n('ADD') + rk.i18n('TITLE_GROUP'),
                        success: function (contentElem) {
                            contentElem.groupCreateNewCtrl({loaddataType:me.loaddataType});
                        },
                        footer: ['cancel', {
                            act: 'ok', visible: true, text: rk.i18n('SAVE')
                        }]
                    });
                });
            });
            elem.on('click','.oa-close-panel',function(){
                rk.oa.closePanel();
            });
        }, 
        //init方法中，用来初始化数据
        _init: function () {
            var me = this;
            var elem = me.element;
            me.loaddata("my_group");
            elem.find('[act="beScroll"]').beScroll();
        },
        loaddataType:"",
        loaddata: function (type, param) {
            var me = this;
            var elem = me.element;
            if(!param){
                param = {pageNo:1,pageSize:20};
            }
            me.loaddataType = type;
            if(type == "all_group"){
                elem.find("[act='group_all_table_list']").beLoading();
                elem.find("[act='group_all_table_list']").groupPanelTableCtrl({type:type});
            }else if(type == "my_group"){
                elem.find("[act='group_my_table_list']").beLoading();
                elem.find("[act='group_my_table_list']").groupPanelTableCtrl({type:type});
            }else if(type == "my_create_group"){
                elem.find("[act='group_my_table_list']").beLoading();
                elem.find("[act='group_my_table_list']").groupPanelTableCtrl({type:type});
            }
        }
    });
});